/*
 *--------------------------------------------------------------------------
 *   File Name:	bits.h
 * 
 * Description:	none
 * 
 * 
 *      Author:	Zhao Yanbai [zhaoyanbai@126.com]
 * 
 *     Version:	1.0
 * Create Date: Wed Mar  4 20:56:29 2009
 * Last Update: Wed Mar  4 20:56:29 2009
 * 
 *--------------------------------------------------------------------------
 */

#ifndef	_BITS_H
#define	_BITS_H

//#define	SET_BIT(bit) (1UL<<bit)
//#define	CLR_BIT(bit) (~(1UL<<bit))
//#define	ISSET_BIT(val,bit) ((val) & SET_BIT(bit))
#define	SET_BIT(val, bit)	(val |= (1UL<<bit))
#define	CLR_BIT(val, bit)	(val &= (~(1UL<<bit)))
#define	XOR_BIT(val, bit)	(btc((unsigned int *)&val, bit), val)
#define	ISSET_BIT(val, bit)	(val & (1UL<<bit))
#define	ISCLR_BIT(val, bit)	(!ISSET_BIT(val, bit))

static inline void btc(unsigned int *v, unsigned int b)
{
	asm ("btc %1,%0":"=m"(*v): "Ir"(b));
}


static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
{
	int oldbit;
/*
	asm volatile("btr %2,%1\n\t"
		     "sbb %0,%0"
		     : "=r" (oldbit), ADDR : "Ir" (nr) : "memory");
*/
	return oldbit;
}


#endif //_BITS_H
